package jd;

/*
CREATE TABLE author (
	id		SERIAL PRIMARY KEY,
	collective_name	VARCHAR,
	last_name	VARCHAR,
	fore_name	VARCHAR,
	initials	VARCHAR,
	affiliation	VARCHAR,
	UNIQUE (collective_name, fore_name, last_name, initials)
);

-- 这个是作者表，也就是链接article和person的一个表
CREATE TABLE author_rel (
	article_id	INTEGER,
	author_id	INTEGER,
	PRIMARY KEY (article_id, author_id)
);
*/

public class Person {
	public String collective_name;
	public String last_name;
	public String fore_name;
	public String initials;
	public String affiliation;
	boolean inited = false;

	void init() {
		if (inited)
			return;

		if (collective_name == null) {
			collective_name = "";
		}
		collective_name = collective_name.replaceAll("'", "''");

		if (last_name == null) {
			last_name = "";
		}
		last_name = last_name.replaceAll("'", "''");

		if (fore_name == null) {
			fore_name = "";
		}
		fore_name = fore_name.replaceAll("'", "''");

		if (initials == null) {
			initials = "";
		}
		initials = initials.replaceAll("'", "''");
		if (affiliation == null) {
			affiliation = "";
		}
		affiliation = affiliation.replaceAll("'", "''");

		inited = true;
	}

	public String to_str() {
		String ret;

		init();

		ret = String.format("'%s', '%s', '%s', '%s', '%s'",
				collective_name, last_name, fore_name, initials,
				affiliation);
		return ret;
	}

	public String to_cond() {
		String ret;

		init();
		ret = String.format("collective_name = '%s' AND " + 
				"last_name = '%s' AND " + 
				"fore_name =  '%s' AND " + 
				"initials = '%s'", collective_name, 
				last_name, fore_name, initials);
		return ret;
	}
}


